/**
 *******************************************************************************
 * @FileName  : att_defs.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-02-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */

#ifndef ATT_DEFS_H_
#define ATT_DEFS_H_

/**
 * Define ATT MTU Size define.
 */
#define ATT_DEFAULT_MTU_SIZE      (23)

#define ATT_AUTH_SIG_LEN          (12) /*!< Authentication signature length */

/**
 * Attribute value max length define.
 */
#define ATT_VALUE_MAX_LEN         (512)
#define ATT_VALUE_MAX_OFFSET      (511)

/**
 * BLE MAX ATT MTU SIZE define.
 */
#define ATT_MAX_MTU_SIZE          (527) //(3B attribute header + 512B attribute value  + 12B signed)

/** @Name GATT Characteristic Properties
 *        Properties for how a characteristic may be interacted with through the ATT Protocol.
 *  @{
 */
#define ATT_PROP_BROADCAST            0x01      /*!< Permit broadcasts */
#define ATT_PROP_READ                 0x02      /*!< Permit reads */
#define ATT_PROP_WRITE_NO_RSP         0x04      /*!< Permit writes without response */
#define ATT_PROP_WRITE                0x08      /*!< Permit writes with response */
#define ATT_PROP_NOTIFY               0x10      /*!< Permit notifications */
#define ATT_PROP_INDICATE             0x20      /*!< Permit indications */
#define ATT_PROP_AUTHENTICATED        0x40      /*!< Permit signed writes */
#define ATT_PROP_EXTENDED             0x80      /*!< More properties defined in extended properties */
/**@}*/

/**
 * Attribute Protocol Opcode define.
 * @{
 */
#define ATT_ERROR_RESPONSE          0x01

#define ATT_MTU_EXCHANGE_REQ        0x02
#define ATT_MTU_EXCHANGE_RSP        0x03

#define ATT_FIND_INFO_REQ           0x04
#define ATT_FIND_INFO_RSP           0x05
#define ATT_FIND_BY_TYPE_VALUE_REQ  0x06
#define ATT_FIND_BY_TYPE_VALUE_RSP  0x07

#define ATT_READ_BY_TYPE_REQ        0x08
#define ATT_READ_BY_TYPE_RSP        0x09
#define ATT_READ_REQ                0x0A
#define ATT_READ_RSP                0x0B
#define ATT_READ_BLOB_REQ           0x0C
#define ATT_READ_BLOB_RSP           0x0D
#define ATT_READ_MULTI_REQ          0x0E /*!< unsupported currently. */
#define ATT_READ_MULTI_RSP          0x0F /*!< unsupported currently. */
#define ATT_READ_BY_GROUP_TYPE_REQ  0x10
#define ATT_READ_BY_GROUP_TYPE_RSP  0x11

#define ATT_WRITE_REQ               0x12
#define ATT_WRITE_RSP               0x13
#define ATT_WRITE_CMD               0x52 /*!< write command             */
#define ATT_SIGNED_WRITE_CMD        0xD2 /*!< write command with signed */

#define ATT_PREPARE_WRITE_REQ       0x16 /*!< unsupported currently. */
#define ATT_PREPARE_WRITE_RSP       0x17 /*!< unsupported currently. */
#define ATT_EXECUTE_WRITE_REQ       0x18 /*!< unsupported currently. */
#define ATT_EXECUTE_WRITE_RSP       0x19 /*!< unsupported currently. */

#define ATT_VALUE_NOTIFY            0x1B /*!< by server initiated */
#define ATT_VALUE_INDICATION        0x1D /*!< by server initiated */
#define ATT_VALUE_COMFIRM           0x1E
/**@}*/

/**
 * @Name:  ATT PDU Length Fields
 *         Length constants of PDU fixed length fields
 * @{
 */
#define ATT_HDR_LEN                   1

#define ATT_ERR_RSP_LEN               5 /*!< Error response length. */
#define ATT_MTU_REQ_LEN               3 /*!< MTU request length. */
#define ATT_MTU_RSP_LEN               3 /*!< MTU response length. */
#define ATT_FIND_INFO_REQ_LEN         5 /*!< Find information request length. */
#define ATT_FIND_INFO_RSP_LEN         2 /*!< Find information response length. */
#define ATT_FIND_TYPE_REQ_LEN         7 /*!< Find type request length. */
#define ATT_FIND_TYPE_RSP_LEN         1 /*!< Find type response length. */
#define ATT_READ_TYPE_REQ_LEN         5 /*!< Read type request length. */
#define ATT_READ_TYPE_RSP_LEN         2 /*!< Read type response length. */
#define ATT_READ_REQ_LEN              3 /*!< Read request length. */
#define ATT_READ_RSP_LEN              1 /*!< Read response length. */
#define ATT_READ_BLOB_REQ_LEN         5 /*!< Read blob request legnth. */
#define ATT_READ_BLOB_RSP_LEN         1 /*!< Read blob response length. */
#define ATT_READ_MULT_REQ_LEN         1 /*!< Read multiple request length. */
#define ATT_READ_MULT_RSP_LEN         1 /*!< Read multiple response length. */
#define ATT_READ_GROUP_TYPE_REQ_LEN   5 /*!< Read group type request length. */
#define ATT_READ_GROUP_TYPE_RSP_LEN   2 /*!< Read group type response length. */
#define ATT_WRITE_REQ_LEN             3 /*!< Write request length. */
#define ATT_WRITE_RSP_LEN             1 /*!< Write response length. */
#define ATT_WRITE_CMD_LEN             3 /*!< Write command length. */
#define ATT_SIGNED_WRITE_CMD_LEN      (ATT_WRITE_CMD_LEN + ATT_AUTH_SIG_LEN) /*!< Signed write command length. */
#define ATT_PREP_WRITE_REQ_LEN        5 /*!< Prepared write command length. */
#define ATT_PREP_WRITE_RSP_LEN        5 /*!< Prepared write response length. */
#define ATT_EXEC_WRITE_REQ_LEN        2 /*!< Execute write request length. */
#define ATT_EXEC_WRITE_RSP_LEN        1 /*!< Execute write response length. */
#define ATT_VALUE_NTF_LEN             3 /*!< Value notification length. */
#define ATT_VALUE_IND_LEN             3 /*!< Value indication length. */
#define ATT_VALUE_CNF_LEN             1 /*!< Value confirmation length. */
/**@}*/


/**
 * @Name: ATT PDU Masks
 * @{
 */
#define ATT_PDU_MASK_SERVER        0x01 /*!< Server bit mask         */
#define ATT_PDU_MASK_COMMAND       0x40 /*!< Command bit mask        */
#define ATT_PDU_MASK_SIGNED        0x80 /*!< Auth signature bit mask */
/**@}*/


/**
 * ATT handle define.
 */
#define ATT_HANDLE_NONE      0x0000
#define ATT_HANDLE_MIN       0x0001
#define ATT_HANDLE_MAX       0xFFFF
/**@}*/


/**
 * @Name: UUID lengths
 */
#define ATT_16_UUID_LEN  2
#define ATT_128_UUID_LEN 16


/**
 * @Name: UUID type
 */
#define UUID_TYPE_INVALID   0x00
#define UUID_TYPE_16        0x01
#define UUID_TYPE_128       0x02


/**
 * @Name:
 */
#define NOTIFY_ENABLE     0x0001
#define INDICATE_ENABLE   0x0002


#endif /* BLH_ATT_DEFS_H_ */
